<template>
	<view class="page">
		<comp-common v-bind="{data:data}"></comp-common>
		<comp-header v-bind="{data:data}"></comp-header>
		<view class="body after-navber">
			<view class="list">
				<view class="no-data-tip" v-if="data.list.length<1">
					<view>你还没有进行中的砍价</view>
					<view>去会场逛逛！</view>
				</view>
				<view class="one flex-row" v-for="(item,index) in data.list" :key="item.id">
					<view class="flex-grow-0" style="width:216upx;height:216upx;margin-right:20upx;">
						<image :src="item.cover_pic"></image>
					</view>
					<view class="flex-grow-1 flex-col">
						<view class="flex-grow-0">
							<view class="text-more-2" style="font-size:9pt">{{item.goods_name}}</view>
						</view>
						<view class="flex-grow-1 flex-col">
							<block v-if="item.reset_time>0&&item.time_list!=undefined">
								<view class="flex-row flex-grow-1 flex-y-center">
									<block v-if="data.time_list.day>0">
										<view class="time flex-y-center">{{item.time_list.d}}</view>
										<view style="margin: 0 10upx;">天</view>
									</block>
									<view class="time flex-y-center">{{item.time_list.h}}</view>
									<view class=" flex-y-center">：</view>
									<view class="time flex-y-center">{{item.time_list.m}}</view>
									<view class=" flex-y-center">：</view>
									<view class="time flex-y-center">{{item.time_list.s}}</view>
									<view class=" flex-y-center" style="margin-left:16upx"> 后结束</view>
								</view>
								<view class="flex-grow-0 flex-row">
									<view class="flex-grow-1">
										<view v-if="item.price>0">
											<view class="a">离最低￥{{item.min_price}}</view>
											<view class="b">还差￥{{item.price}}</view>
										</view>
										<view v-else>
											<view class="a">已砍至最低</view>
											<view class="b">￥{{item.min_price}}</view>
										</view>
									</view>
									<view class="flex-grow-0 flex-y-bottom">
										<navigator class="list-btn flex-x-center flex-y-center" hoverClass="none" :url="'/bargain/activity/activity?order_id='+item.order_id"
										 v-if="item.price>0">继续砍价</navigator>
										<view @click="submit" class="list-btn flex-x-center flex-y-center" :data-index="item.order_id" v-else>立即购买</view>
									</view>
								</view>
							</block>
							<block v-else>
								<view class="flex-grow-1" style="margin-top:40upx;color:#666;">已结束</view>
								<view class="flex-grow-0" :style="{color:item.status==1?'#ff5c5c':'#999'}">{{item.content}}</view>
							</block>
						</view>
					</view>
				</view>
			</view>
			<com-naver v-bind="{data:data}"></com-naver>
		</view>
		<comp-footer v-bind="{data:data}"></comp-footer>
	</view>

</template>

<script>var myVue = {};
import comNaver from './../commons/naver/naver.vue'
var t = !1, e = !0, a = null;
	export default {
		components:{
			comNaver
		},
		data() {
			return {
				data: {
					naver: "order",
					status: -1,
					intval: [],
					p: 1,
					list: {},
					time_list: {},
				}
			}
		},
		onLoad: function(t) {myVue = this;
			var e = this;
			myVue.getApp.page.onLoad(this, t);

			void 0 == t.status && (t.status = -1), e.setData(t), e.getList();
		},
		onReady: function() {
			myVue.getApp.page.onReady(this);
		},
		onShow: function() {
			myVue.getApp.page.onShow(this);
		},
		onHide: function() {
			myVue.getApp.page.onHide(this);
		},
		onUnload: function() {
			myVue.getApp.page.onUnload(this);
		},
		onReachBottom: function() {
			var t = this;
			e || t.loadData();
		},
		methods: {
			getList: function() {
				var t = this;
											    t.getApp.core.showLoading({
											        title: "加载中"
											    }),
				t.getApp.request({
					url: t.getApp.api.bargain.order_list,
					data: {
						status: t.data.status || -1
					},
					success: function(e) {
						0 == e.code ? (t.setData(e.data), t.setData({
							p: 1
						}), t.getTimeList()) : t.showLoading({
							title: e.msg
						});
					},
					complete: function(t) {
						myVue.getApp.core.hideLoading(), e = !1;
					}
				});
			},
			getTimeList: function() {
				clearInterval(a);
				var t = this,
					e = t.data.list;
				console.log(e)
				var a = setInterval(function() {
					for (var a in e)
						if (e[a].reset_time > 0) {
							var i = e[a].reset_time - 1,
								s = t.setTimeList(i);
							e[a].reset_time = i, e[a].time_list = s;
						}
					t.setData({
						list: e
					});
				}, 1e3);
			},
			loadData: function() {
				var a = this;
				if (!t) {
										t = !0, a.getApp.core.showLoading({
											title: "加载中"
										});
					var i = a.data.p + 1;
					a.getApp.request({
						url: a.getApp.api.bargain.order_list,
						data: {
							status: a.data.status,
							page: i
						},
						success: function(t) {
							if (0 == t.code) {
								var s = a.data.list.concat(t.data.list);
								a.setData({
										list: s,
										p: i
									}), 0 == t.data.list.length && (e = !0),
									a.getTimeList();
							} else a.showLoading({
								title: t.msg
							});
						},
						complete: function(e) {
							a.getApp.core.hideLoading(), t = !0;
						}
					});
				}
			},
			submit: function(t) {
				var that = this;
				var e = [],
					a = [];
				a.push({
					bargain_order_id: t.currentTarget.dataset.index
				}), e.push({
					store_id: 0,
					goods_list: a
				}), that.getApp.core.navigateTo({
					url: "/pages/new-order-submit/new-order-submit?store_list=" + JSON.stringify(e)
				});
			}
		}
	}
</script>

<style scoped>
	.list {
		width: 100%;
		padding-bottom: 96upx;
		border-top: 1upx solid #e2e2e2;
	}

	.one {
		width: 100%;
		padding: 24upx 20upx;
		margin-bottom: 8upx;
		background-color: #fff;
		font-size: 9pt;
	}

	.one image {
		width: 216upx;
		height: 216upx;
	}

	.time {
		width: auto;
		height: 36upx;
		background-color: #666;
		border-radius: 4upx;
		color: #fff;
		padding: 0 6upx;
	}

	.a {
		color: #999;
		margin-bottom: 4upx;
		font-size: 9pt;
	}

	.b {
		color: #ff5c5c;
	}

	.list-btn {
		width: 176upx;
		height: 64upx;
		border-radius: 32upx;
		color: #fff;
		background-color: #ff5c5c;
		font-size: 11pt;
	}

	.img {
		width: 18upx;
		height: 18upx;
		margin-left: 12upx;
	}

	.img.up {
		transform: rotate(90deg);
	}
</style>
